import net from "net";

const html = `<h1>TCP Server</h1>`

const reposneHeader = [
    'HTTP/1.1 200 OK',
    'Content-Type: text/html',
    'Content-Length: ' + html.length,
    'Server: Nodejs',
    '\r\n',
    html
]


// 创建一个服务端
const server = net.createServer((socket) => {
  socket.on("data", (data) => {
    if(/GET/.test(data.toString())) {
        socket.write(reposneHeader.join('\r\n'))
        socket.end()
    }
  });
});

server.listen(3000, () => {
  console.log("Server is running on port 3000");
});
